// components/comment/commentItem.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    info: { 
        type: Object,
        value: {}
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    animationData: {},
    isResponsing: false,
    isMore: false,
    isShowAll: true,
  },
  ready: function() {
    const animation = wx.createAnimation({
      duration: 500,
      timingFunction: 'ease',
    })
    this.animation = animation
    const that = this;
    wx.createSelectorQuery().in(this).select('#comment-content-' + this.data.info.id).boundingClientRect(function(rect){
      const height = rect.height;
      that.setData({ isMore: height > 50, isShowAll: false });
    }).exec()
  },
  /**
   * 组件的方法列表
   */
  methods: {
    onChangeShowAllAction: function () {
      const { isMore, isShowAll } = this.data;
      if(isMore) {
        const degree = isShowAll ? 360 :  180;
        this.animation.rotate(degree).step()
        this.setData({
          animationData: this.animation.export()
        })
        this.setData({ isShowAll: !isShowAll });
      }
    },
    onClickItemAction: function () {
      const that = this;
      if (this.data.isResponsing) {
          return;
      }
      this.data.isResponsing = true;
      this.triggerEvent("onClickAction", this.data.info);
      setTimeout(function () {
          that.data.isResponsing = false;
      }, 500);
    },
    onClickCommentPicAction: function (ev) {
      let currentUrl = ev.currentTarget.dataset.picurl
      wx.previewImage({
        current: currentUrl, // 当前显示图片的http链接
        urls: this.data.info.picList // 需要预览的图片http链接列表
      })
    }
  }
})
